/*
 * Copyright (C) 2010 Enrique Lara (enrique.posix2.lara@gmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package app.tellwmata.model;

import android.content.Context;
import android.content.Intent;

import android.util.Log;

import android.widget.Toast;

import app.tellwmata.Constants;
import static app.tellwmata.Constants.ACTION_ABOUT;
import static app.tellwmata.Constants.ACTION_PROFILE;
import static app.tellwmata.Constants.ACTION_SETTINGS;

import java.io.PrintWriter;
import java.io.StringWriter;

public final class App {
    private static final String TAG = "App";
    private final Context context;

    public App(final Context context) {
        this.context = context;
    }

    public static void showError(final Context c, final String msg, final Throwable e) {
        try {
            StringWriter sw = new StringWriter();
            PrintWriter writer = new PrintWriter(sw);
            e.printStackTrace(writer);
            Toast.makeText(c, msg + sw, Toast.LENGTH_LONG).show();
            Log.e(TAG, msg, e);
        } catch (Throwable e2) {
            throw new RuntimeException("Failure Toasting Exception", e);
        }
    }

    public boolean gotoBuses() {
        final Intent intent = new Intent(Constants.ACTION_METRO);
        intent.putExtra(Constants.FormFields.ROUTE_TYPE, Constants.TYPE_BUS);
        context.startActivity(intent);

        return true;
    }

    public boolean gotoMetro() {
        final Intent intent = new Intent(Constants.ACTION_METRO);
        intent.putExtra(Constants.FormFields.ROUTE_TYPE, Constants.TYPE_METRO);
        context.startActivity(intent);

        return true;
    }

    public boolean gotoParatransit() {
        final Intent intent = new Intent(Constants.ACTION_METRO);
        intent.putExtra(Constants.FormFields.ROUTE_TYPE, Constants.TYPE_PARATRANSIT);
        context.startActivity(intent);

        return true;
    }

    public boolean gotoSettings() {
        context.startActivity(new Intent(ACTION_SETTINGS));

        return true;
    }

    public boolean gotoProfile() {
        context.startActivity(new Intent(ACTION_PROFILE));

        return true;
    }

    public boolean gotoAbout() {
        context.startActivity(new Intent(ACTION_ABOUT));

        return true;
    }
}
